<?php

class TestMethod {
  var $name;
  var $assertions;
  var $passed=true;
  var $output;
  private $class_name;

  function __construct($name="", $class_name="") {
    $this->name = $name;
    $this->class_name = $class_name;
    $this->assertions = array();
  }

  function add_assertion($assertion) {
    $this->passed &= $assertion->passed;
    $this->assertions[] = $assertion;
  }

  function div_id() {
    return $this->class_name . "." . $this->name;
  }

  function assertions_class() {
    return !$this->passed ? "Selected" : "";
  }

  function assertionsToHtml() {
    $div_id = $this->div_id();    
    $html .= "<div id=\"$div_id.Assertions\" class=\"TabPane "
              . $this->assertions_class() . "\">"
             . "<ol>";
                  foreach($this->assertions as $assertion) {
                    $html .= $assertion->toHtml();
                  }
    $html .=   "</ol>"
           . "</div>";

    return $html;
  }

  function tabsToHtml() {
    $div_id = $this->div_id();
    $assertions_class = 

    $html .= "<div class=\"Tabs\">"
             . "<a id=\"$div_id.AssertionsTab\" "
               . "href=\"javascript:tab_click('$div_id.Assertions');\" "
               . " class=\"" . $this->assertions_class() 
               . "\">Assertions"
             . "</a>";


    if ($this->output) {
      $html .= "<a id=\"$div_id.OutputTab\" "
               . "href=\"javascript:tab_click('$div_id.Output');\">"
               . "Output"
             . "</a>";
    }

    $html .= "</div>";
    return $html;
  }

  function outputToHtml() {
    $div_id = $this->div_id();
    if ($this->output) {
      $html .= "<div class=\"TabPane\" id=\"$div_id.Output\">"
                . htmlentities($this->output)
             . "</div>";
    }
    return $html;
  }

  function resultsToHtml() {
    $html = "<div class=\"Results TabGroup\">"
            . $this->tabsToHtml()
            . $this->assertionsToHtml()
            . $this->outputToHtml()
          . "</div>";

    return $html;
  }

  function toHtml($odd = false) {
    $odd_class = $odd ? "Odd" : "Even";
    $result = $this->passed ? "Pass" : "Fail";

    $html = "<div class=\"Method $odd_class\">"
            . "<div class=\"Line\"><span>line&nbsp;$this->line</span></div>"
            . "<div class=\"Name $result\">$this->name:</div>"
            . $this->resultsToHtml()
          . "</div>";

    return $html;
  }
}

?>
